﻿
layui.use(function () {
    var table = layui.table;
    var form = layui.form;
    
    $.ajax({
        url: "/GualityGroup/GualityGroupSelect",
        type: "get",
        data: { token: localStorage.getItem("token") },
        success: function (data) {
            var data = JSON.parse(data);
            var options = '<option value="">请选择质检组</option>'; // 添加默认选项
            $.each(data.data, function (index, item) {
                options += '<option value="' + item.gualityGroupId + '">' + item.gualityGroupName + '</option>';
            });
            $("#gualityGroupId").html(options);
            form.render('select'); // 重新渲染下拉框
        },
        error: function () {
            console.log("获取数据失败");
            // 可以考虑显示一个错误消息给用户
        }
    });
    function editData() {
        table.render({
            elem: '#carriertable',  // 表格元素的选择器
            cols: [[
                { type: 'checkbox', fixed: 'left' },
                { field: 'gualityProjectName', title: '质检项目名称' },
                { field: 'gualityProjectNumbering', title: '质检项目编号' },
                { field: 'gualityProjectTool', title: '质检方法' },
                { field: 'gualityProjectMethod', title: '质检工具' },
                { field: 'gualityProjectType', title: '质检类型' },
                { field: 'gualityProjectStandardValue', title: '标准值' },
                { field: 'gualityProjectUnderDifference', title: '上差值' },
                {
                    field: 'gualityProjectAboveDifference', title: '下差值' },
            ]],
            // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
            data: []
        });
        $.ajax({
            type: "get",
            url: "/GualityScheme/GualitySchemeModel",  // 替换为实际的后台根据id获取数据的接口地址
            data: { gualitySchemeId: sessionStorage.getItem("gualitySchemeId"), token: localStorage.getItem("token") },
            success: function (res) {
                var res = JSON.parse(res)
                table.reload('carriertable', {
                    data: res.data.plist
                });
                console.log(res)
                $(res.data).each(function () {
                    $('#gualitySchemeNumbering').val(this.gualitySchemeNumbering)
                    $('#gualitySchemeName').val(this.gualitySchemeName)
                    $('#gualitySchemeState').val(this.gualitySchemeState)
                    $('#gualityGroupId').val(this.gualityGroupId)
                    form.render('select');
                })
            },
        });
        
        // 创建表格实例 

    }
    $(function () {
        editData();
    })
})
function formatTime(timeStamp) {
    if (timeStamp) {
        var date = new Date(timeStamp);
        var year = date.getFullYear();
        var month = ('0' + (date.getMonth() + 1)).slice(-2);
        var day = ('0' + date.getDate()).slice(-2);
        var hour = ('0' + date.getHours()).slice(-2);
        var minute = ('0' + date.getMinutes()).slice(-2);
        var second = ('0' + date.getSeconds()).slice(-2);
        return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
    }
    return "";
}
function ChangeState(state) {
    debugger
    if (state == true) {
        return "启用"
    }
    else {
        return "禁用"
    }
}
